package qc.module.qms.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.qms.dto.exchange.channel.ExchangeChannelDto;
import qc.module.qms.service.ExchangeChannelService;

import java.util.List;

/**
 * ExchangeChannelController
 * 数据交换通道
 *
 * @author QuCheng Tech
 * @since 2024/1/23
 */
@RestController
@RequestMapping("/exchchannel")
public class ExchangeChannelController {
    
    @Autowired
    private ExchangeChannelService service;

    /**
     * 获取所有
     * 
     * @return List<ExchangeChannelDto> 返回交换通道集合
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @GetMapping("/all")
    public List<ExchangeChannelDto> getAll(){
        return service.getAll();
    }

    /**
     * 获取指定
     * 
     * @param id 交换通道ID
     * @return ExchangeChannelDto 返回指定交换通道信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @GetMapping("/get")
    public ExchangeChannelDto getByParam(@RequestParam Integer id){
        return service.get(id);
    }

    /**
     * 获取指定
     * 
     * @param id 交换通道ID
     * @return ExchangeChannelDto 返回指定交换通道信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @GetMapping("/get/{id}")
    public ExchangeChannelDto getByPath(@PathVariable Integer id){
        return service.get(id);
    }

    /**
     * 新增
     * 
     * @return 成功返回null，失败返回错误信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @RequestMapping(value = "/add",method = {RequestMethod.GET,RequestMethod.POST})
    public String add(@RequestBody ExchangeChannelDto dto){
        return service.add(dto);
    }

    /**
     * 修改
     * 
     * @return 成功返回null，失败返回错误信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @RequestMapping(value = "/update",method = {RequestMethod.POST,RequestMethod.PUT})
    public String update(@RequestBody ExchangeChannelDto dto){
        return service.update(dto);
    }

    /**
     * 删除
     * 
     * @param id 交换通道ID
     * @return 成功返回null，失败返回错误信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @DeleteMapping("/delete")
    public String deleteByParam(@RequestParam Integer id) throws QCPromptException {
        return service.delete(id);
    }

    /**
     * 删除
     * 
     * @param id 交换通道ID
     * @return 成功返回null，失败返回错误信息
     * @author QuCheng Tech
     * @since 2024/4/16
     */
    @DeleteMapping("/delete/{id}")
    public String deleteByPath(@PathVariable Integer id) throws QCPromptException {
        return service.delete(id);
    }
}
